<?php
ob_start();
require_once("../../inc/global.php");

$get=getParameters();


$menuinfo=$db->getoners('select * from menusys where menusys0='.$get['menuid'].' limit 1');
//print_r($menuinfo);

$tpl=new tpl();

ob_clean();
## 单页面
$table = $menuinfo['menusys8'];
if($get['type']=='onepage'){
	
	## PC端静态
	if(!empty($menuinfo['menusys13']) && !empty($menuinfo['menusys19'])){
		ob_clean();
		$tpl->display($menuinfo['menusys13'],$menuinfo['menusys8'],$get['menuid']);
		$contents = ob_get_contents();
		ob_clean();
		if(isset($_GET['debug']) && isset($_GET['client']) && $_GET['client']=='pc'){
			echo $contents;
			exit();
		}
		$menuinfo['menusys19'] = strtr($menuinfo['menusys19'],array('{menuid}'=>$get['menuid']));
		$savepath = strtr(SITEROOT.$menuinfo['menusys19'],array('/'=>XG));
		$p=pathinfo($savepath);
		if(!file_exists($p['dirname'])) mkdir($p['dirname'],0777,true);
		file_put_contents($savepath,$contents);
		header('PC-Static:'.$menuinfo['menusys19']);
		header('PC-Status:ok');
		$s=$db->query('update '.$table.' set '.$table.'2="'.strtr($menuinfo['menusys19'],array('{menuid}'=>$get['menuid'])).'" where '.$table.'1='.$get['menuid']. ' limit 1');
		// $rarray[] = $menuinfo['menusys19'];
		if(DEBUG){
			$rarray[] = $menuinfo['menusys19'].'{debugspsplit}/'.ADMINROOT.'/System/htmlsys/createhtml.php?'.$_SERVER['QUERY_STRING'].'&debug=true&client=pc';
		}else{
			$rarray[] = $menuinfo['menusys19'].'{debugspsplit}false';
		}
	}
	## 移动端静态
	if(!empty($menuinfo['mmenusys13']) && !empty($menuinfo['mmenusys19'])){
		ob_clean();
		$tpl->display($menuinfo['mmenusys13'],$menuinfo['menusys8'],$get['menuid']);
		$contents = ob_get_contents();
		ob_clean();
		if(isset($_GET['debug']) && isset($_GET['client']) && $_GET['client']=='m'){
			echo $contents;
			exit();
		}
		$menuinfo['mmenusys19'] = strtr($menuinfo['mmenusys19'],array('{menuid}'=>$get['menuid']));
		$savepath = strtr(SITEROOT.$menuinfo['mmenusys19'],array('/'=>XG));
		$p=pathinfo($savepath);
		if(!file_exists($p['dirname'])) mkdir($p['dirname'],0777,true);
		file_put_contents($savepath,$contents);
		header('M-Static:'.$menuinfo['mmenusys19']);
		header('M-Status:ok');
		$s=$db->query('update '.$table.' set '.$table.'3="'.strtr($menuinfo['mmenusys19'],array('{menuid}'=>$get['menuid'])).'" where '.$table.'1='.$get['menuid']. ' limit 1');
		// $rarray[] = $menuinfo['mmenusys19'];
		if(DEBUG){
			$rarray[] = $menuinfo['mmenusys19'] . '{debugspsplit}/'.ADMINROOT.'/System/htmlsys/createhtml.php?'.$_SERVER['QUERY_STRING'].'&debug=true&client=m';
		}else{
			$rarray[] = $menuinfo['mmenusys19'].'{debugspsplit}false';
		}
	}
	if(count($rarray)>0){
		//echo '<div style="font-size:12px;">'.implode(',',$rarray).'</div>';
		echo '<div style="font-size:12px;">'.strtr(implode(',',$rarray),array('{debugspsplit}false'=>'','{debugspsplit}'=>',')).'</div>';
		echo '<script type="text/javascript">parent.rundataurl("'.implode('","',$rarray).'");</script>';
	}
	
}elseif($get['type']=='detail'){
	//print_r($menuinfo);
	//exit();
	
	if(isset($get['id'])){
		## PC端静态
		$rarray = array();
		if(!empty($menuinfo['menusys17']) && !empty($menuinfo['menusys16'])){
			ob_clean();
			$tpl->display($menuinfo['menusys17'],$menuinfo['menusys8'],$get['id']);
			$contents = ob_get_contents();
			ob_clean();
			if(isset($_GET['debug']) && isset($_GET['client']) && $_GET['client']=='pc'){
				echo $contents;
				exit();
			}
			$menuinfo['menusys16'] = strtr($menuinfo['menusys16'],array('{$id}'=>$get['id']));
			$savepath = strtr(SITEROOT.$menuinfo['menusys16'],array('/'=>XG));
			$p=pathinfo($savepath);
			if(!file_exists($p['dirname'])) mkdir($p['dirname'],0777,true);
			file_put_contents($savepath,$contents);
			header('PC-Static:'.$menuinfo['menusys16']);
			header('PC-Status:ok');
			$s=$db->query('update '.$table.' set '.$table.'2="'.$menuinfo['menusys16'].'" where '.$table.'0='.$get['id']. ' limit 1');
			//$rarray[] = $menuinfo['menusys16'];
			if(DEBUG){
				$rarray[] = $menuinfo['menusys16'] . '{debugspsplit}/'.ADMINROOT.'/System/htmlsys/createhtml.php?'.$_SERVER['QUERY_STRING'].'&debug=true&client=pc';
			}else{
				$rarray[] = $menuinfo['menusys16'].'{debugspsplit}false';
			}
		}
		
		## 移动端静态
		if(!empty($menuinfo['mmenusys17']) && !empty($menuinfo['mmenusys16'])){
			ob_clean();
			$tpl->display($menuinfo['mmenusys17'],$menuinfo['menusys8'],$get['id']);
			$contents = ob_get_contents();
			ob_clean();
			if(isset($_GET['debug']) && isset($_GET['client']) && $_GET['client']=='m'){
				echo $contents;
				exit();
			}
			
			$menuinfo['mmenusys16'] = strtr($menuinfo['mmenusys16'],array('{$id}'=>$get['id']));
			$savepath = strtr(SITEROOT.$menuinfo['mmenusys16'],array('/'=>XG));
			$p=pathinfo($savepath);
			if(!file_exists($p['dirname'])) mkdir($p['dirname'],0777,true);
			file_put_contents($savepath,$contents);
			header('M-Static:'.$menuinfo['mmenusys16']);
			header('M-Status:ok');
			$s=$db->query('update '.$table.' set '.$table.'3="'.$menuinfo['mmenusys16'].'" where '.$table.'0='.$get['id']. ' limit 1');
			//$rarray[] = $menuinfo['mmenusys16'];
			if(DEBUG){
				$rarray[] = $menuinfo['mmenusys16'] . '{debugspsplit}/'.ADMINROOT.'/System/htmlsys/createhtml.php?'.$_SERVER['QUERY_STRING'].'&debug=true&client=m';
			}else{
				$rarray[] = $menuinfo['mmenusys16'].'{debugspsplit}false';
			}
			
		}
		if(count($rarray)>0){
			//echo '<div style="font-size:12px;">'.implode(',',$rarray).'</div>';
			echo '<div style="font-size:12px;">'.strtr(implode(',',$rarray),array('{debugspsplit}false'=>'','{debugspsplit}'=>',')).'</div>';
			echo '<script type="text/javascript">parent.rundataurl("'.implode('","',$rarray).'");</script>';
		}
	}else{
		header('HTTP/1.1 500 Internal Server Error');
	}
	


}elseif($get['type']=='list'){
	## PC端静态
	if($get['rukou']=='pc'){
		
		if(!empty($menuinfo['menusys14']) && !empty($menuinfo['menusys15'])){
			ob_clean();
			$tpl->display($menuinfo['menusys15'],$menuinfo['menusys8'],false);
			$contents = ob_get_contents();
			ob_clean();
			if(isset($_GET['debug']) && isset($_GET['client']) && $_GET['client']=='pc'){
				echo $contents;
				exit();
			}
			
			if(isset($get['isstatusinfo']) && $get['isstatusinfo']=='true'){
				exit();
			}
			$page = '1';
			if(isset($get['page'])) $page = $get['page'];
			$menuinfo['menusys14'] = strtr($menuinfo['menusys14'],array('{$cid}'=>$get['classid'],'{$page}'=>$page));
			$savepath = strtr(SITEROOT.$menuinfo['menusys14'],array('/'=>XG));
			$p=pathinfo($savepath);
			if(!file_exists($p['dirname'])) mkdir($p['dirname'],0777,true);
			file_put_contents($savepath,$contents);
			header('PC-Static:'.$menuinfo['menusys14']);
			header('PC-Status:ok');
			echo '<div style="font-size:12px;">'.$menuinfo['menusys14'].'</div>';
			if(DEBUG){
				$returnurl = $menuinfo['menusys14'] . '{debugspsplit}/'.ADMINROOT.'/System/htmlsys/createhtml.php?'.$_SERVER['QUERY_STRING'].'&debug=true&client=pc';
			}else{
				$returnurl = $menuinfo['menusys14'].'{debugspsplit}false';
			}
			echo '<div style="font-size:12px;">'.strtr($returnurl,array('{debugspsplit}false'=>'','{debugspsplit}'=>',')).'</div>';
			echo '<script type="text/javascript">parent.rundataurl("'.$returnurl.'");</script>';
		}
	}
	## 移动端静态
	
	if($get['rukou']=='m'){
		if(!empty($menuinfo['mmenusys14']) && !empty($menuinfo['mmenusys15'])){
			ob_clean();
			$tpl->display($menuinfo['mmenusys15'],$menuinfo['menusys8'],false);
			$contents = ob_get_contents();
			ob_clean();
			if(isset($_GET['debug']) && isset($_GET['client']) && $_GET['client']=='m'){
				echo $contents;
				exit();
			}
			
			if(isset($get['isstatusinfo']) && $get['isstatusinfo']=='true'){
				exit();
			}
			$page = '1';
			if(isset($get['page'])) $page = $get['page'];
			$menuinfo['mmenusys14'] = strtr($menuinfo['mmenusys14'],array('{$cid}'=>$get['classid'],'{$page}'=>$page));
			$savepath = strtr(SITEROOT.$menuinfo['mmenusys14'],array('/'=>XG));
			$p=pathinfo($savepath);
			if(!file_exists($p['dirname'])) mkdir($p['dirname'],0777,true);
			file_put_contents($savepath,$contents);
			header('PC-Static:'.$menuinfo['mmenusys14']);
			header('PC-Status:ok');
			echo '<div style="font-size:12px;">'.$menuinfo['mmenusys14'].'</div>';
			
			if(DEBUG){
				$returnurl = $menuinfo['mmenusys14'] . '{debugspsplit}/'.ADMINROOT.'/System/htmlsys/createhtml.php?'.$_SERVER['QUERY_STRING'].'&debug=true&client=m';
			}else{
				$returnurl = $menuinfo['mmenusys14'].'{debugspsplit}false';
			}
			echo '<div style="font-size:12px;">'.strtr($returnurl,array('{debugspsplit}false'=>'','{debugspsplit}'=>',')).'</div>';
			echo '<script type="text/javascript">parent.rundataurl("'.$returnurl.'");</script>';
			
		}
	}
	
	
	
	
	
}
